package com.gqj.meter.controller;

import com.gqj.common.core.controller.BaseController;
import com.gqj.common.core.domain.AjaxResult;
import com.gqj.common.core.domain.BaseEntity;
import com.gqj.meter.domain.MdInTask;
import com.gqj.meter.domain.MdOutTask;
import com.gqj.meter.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 大屏接口Controller（仅查询，不可添加更新操作接口，无权限认证）
 *
 * @author lxq
 * @date lxq-03-03
 */
@Api(value = "/meter/mdScreen", description = "大屏接口")
@RestController
@RequestMapping("/meter/mdScreen")
public class MdScreenController extends BaseController {
    @Autowired
    private IMdInTaskDetailsService mdInTaskDetailsService;
    @Autowired
    private IMdOutTaskDetailsService mdOutTaskDetailsService;
    @Autowired
    private IMdMeterService mdMeterService;
    @Autowired
    private IMdWarningInfoService mdWarningInfoService;
    @Autowired
    private IMdInTaskService mdInTaskService;
    @Autowired
    private IMdStockPosInfoService mdStockPosInfoService;
    @Autowired
    private IMdOutTaskService mdOutTaskService;
    @Autowired
    private IMdOtherMaterialService mdOtherMaterialService;
    @Autowired
    private IMdItService mdItService;
    @Autowired
    private IMdLcEquipService mdLcEquipService;
    @Autowired
    private IMdConcentratorService mdConcentratorService;
    @Autowired
    private IMdComModuleService mdComModuleService;

    /**
     * 测试接口
     */
    @ApiOperation("获取出入库数量")
    @GetMapping("/getIoNum")
    public AjaxResult getIoNum() {
        Map<String, Object> inNumInfo = mdInTaskDetailsService.getInNumInfo();
        Map<String, Object> outNumInfo = mdOutTaskDetailsService.getOutNumInfo();
        inNumInfo.putAll(outNumInfo);
        return success(inNumInfo);
    }

    /**
     * 获取资产统计信息
     */
    @ApiOperation("获取资产统计信息")
    @GetMapping("/getMaterialStatisticsInfo")
    public AjaxResult getMaterialStatisticsInfo(String curStatusCode) {
        List<Map<String, Object>> map = mdMeterService.getMaterialStatisticsInfo(curStatusCode);
        return success(map);
    }

    /**
     * 查询告警信息列表
     */
    @ApiOperation("报警数量查询")
    @GetMapping("/getWarningCounts")
    public AjaxResult getWarningCounts() {
        return success(mdWarningInfoService.getWarningCounts());
    }

    /**
     * 查询出入库统计信息
     */
    @ApiOperation("查询出入库统计信息")
    @GetMapping("/getIoStatisticsInfo")
    public AjaxResult getIoStatisticsInfo() {
        Map<String, Object> map = mdInTaskService.getIoStatisticsInfo();
        return success(map);
    }

    /**
     * 获取储位统计信息
     */
    @ApiOperation("获取储位统计信息")
    @GetMapping("/getStockStatistics")
    public AjaxResult getStockStatistics() {
        List<Map<String, String>> map = mdStockPosInfoService.getStockStatistics();
        return success(map);
    }

    /**
     * 查询任务信息
     */
    @ApiOperation("查询任务信息")
    @GetMapping("/getTaskInfo")
    public AjaxResult getTaskInfo(BaseEntity baseEntity) {

        MdInTask mdInTask = new MdInTask();
        mdInTask.setParams(baseEntity.getParams());
        startPage();
        List<MdInTask> listIn = mdInTaskService.selectMdInTaskList(mdInTask);

        MdOutTask mdOutTask = new MdOutTask();
        mdOutTask.setParams(baseEntity.getParams());
        startPage();
        List<MdOutTask> listOut = mdOutTaskService.selectMdOutTaskList(mdOutTask);

        Map<String, Object> taskMap = new HashMap<>();
        taskMap.put("inTask", listIn);
        taskMap.put("outTask", listOut);
        return success(taskMap);
    }

    /**
     * 获取储位利用数量比例
     */
    @ApiOperation("获取储位利用数量比例")
    @GetMapping("/getUseStockTotalScale")
    public AjaxResult getUseStockTotalScale() {
        return success(mdStockPosInfoService.getUseStockTotalScale());
    }

    /**
     * 查询业务状态数量
     */
    @ApiOperation("查询业务状态数量")
    @GetMapping("/getServiceStatusNum")
    public AjaxResult getServiceStatusNum() {
        int[] meterNum = mdMeterService.getServiceStatusNum();
        int[] itNum = mdItService.getServiceStatusNum();
        int[] lcEquipNum = mdLcEquipService.getServiceStatusNum();
        int[] comMoudleNum = mdComModuleService.getServiceStatusNum();
        int[] concentratorNum = mdConcentratorService.getServiceStatusNum();
        int[] otherNum = mdOtherMaterialService.getServiceStatusNum();

        Map<String, Object> map = new HashMap<>();
        map.put("电能表", meterNum);
        map.put("互感器", itNum);
        map.put("采集终端", lcEquipNum);
        map.put("模块", comMoudleNum);
        map.put("采集器", concentratorNum);
        map.put("其他物资", otherNum);
        return success(map);
    }

    @ApiOperation("获取设备利用率数据")
    @PostMapping("/getEquipmentUseData")
    public AjaxResult getEquipmentUseData() {
        return success(mdInTaskDetailsService.getTaskDetailsEquipment());
    }
}
